package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.storeOrderCartFee.IDeleteStoreOrderCartFeeBMO;
import com.java110.mall.cart.bmo.storeOrderCartFee.ISaveStoreOrderCartFeeBMO;
import com.java110.mall.cart.bmo.storeOrderCartFee.IUpdateStoreOrderCartFeeBMO;
import com.java110.po.storeOrder.StoreOrderCartFeePo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/storeOrderCartFee")
public class StoreOrderCartFeeApi {

    @Autowired
    private ISaveStoreOrderCartFeeBMO saveStoreOrderCartFeeBMOImpl;
    @Autowired
    private IUpdateStoreOrderCartFeeBMO updateStoreOrderCartFeeBMOImpl;
    @Autowired
    private IDeleteStoreOrderCartFeeBMO deleteStoreOrderCartFeeBMOImpl;



    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartFee/saveStoreOrderCartFee
     * @path /app/storeOrderCartFee/saveStoreOrderCartFee
     */
    @RequestMapping(value = "/saveStoreOrderCartFee", method = RequestMethod.POST)
    public ResponseEntity<String> saveStoreOrderCartFee(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "detailId", "请求报文中未包含detailId");
        Assert.hasKeyAndValue(reqJson, "cartId", "请求报文中未包含cartId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "price", "请求报文中未包含price");
        Assert.hasKeyAndValue(reqJson, "payPrice", "请求报文中未包含payPrice");
        Assert.hasKeyAndValue(reqJson, "payWay", "请求报文中未包含payWay");
        Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含state");
        Assert.hasKeyAndValue(reqJson, "feeConfigId", "请求报文中未包含feeConfigId");
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "updateTime", "请求报文中未包含updateTime");


        StoreOrderCartFeePo storeOrderCartFeePo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartFeePo.class);
        return saveStoreOrderCartFeeBMOImpl.save(storeOrderCartFeePo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartFee/updateStoreOrderCartFee
     * @path /app/storeOrderCartFee/updateStoreOrderCartFee
     */
    @RequestMapping(value = "/updateStoreOrderCartFee", method = RequestMethod.POST)
    public ResponseEntity<String> updateStoreOrderCartFee(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "detailId", "请求报文中未包含detailId");
        Assert.hasKeyAndValue(reqJson, "cartId", "请求报文中未包含cartId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "price", "请求报文中未包含price");
        Assert.hasKeyAndValue(reqJson, "payPrice", "请求报文中未包含payPrice");
        Assert.hasKeyAndValue(reqJson, "payWay", "请求报文中未包含payWay");
        Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含state");
        Assert.hasKeyAndValue(reqJson, "feeConfigId", "请求报文中未包含feeConfigId");
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "detailId", "detailId不能为空");
        Assert.hasKeyAndValue(reqJson, "updateTime", "请求报文中未包含updateTime");


        StoreOrderCartFeePo storeOrderCartFeePo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartFeePo.class);
        return updateStoreOrderCartFeeBMOImpl.update(storeOrderCartFeePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartFee/deleteStoreOrderCartFee
     * @path /app/storeOrderCartFee/deleteStoreOrderCartFee
     */
    @RequestMapping(value = "/deleteStoreOrderCartFee", method = RequestMethod.POST)
    public ResponseEntity<String> deleteStoreOrderCartFee(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺ID不能为空");

        Assert.hasKeyAndValue(reqJson, "detailId", "detailId不能为空");


        StoreOrderCartFeePo storeOrderCartFeePo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartFeePo.class);
        return deleteStoreOrderCartFeeBMOImpl.delete(storeOrderCartFeePo);
    }


}
